package com.sgcc.fj.pmos.e_fj_home.presenter;

import com.alibaba.android.arouter.utils.TextUtils;
import com.blankj.utilcode.util.ToastUtils;
import com.sgcc.fj.pmos.common.base.BasePresenter;
import com.sgcc.fj.pmos.common.http.HttpInterConst;
import com.sgcc.fj.pmos.common.http.HttpRequestUtils;
import com.sgcc.fj.pmos.common.http.MvpNetCallback;
import com.sgcc.fj.pmos.common.utils.UserManager;
import com.sgcc.fj.pmos.e_fj_home.bean.InformationDisclosure2Bean;
import com.sgcc.fj.pmos.e_fj_home.bean.InformationDisclosureBean;
import com.sgcc.fj.pmos.e_fj_home.contract.InformationDisclosureContract;

import java.util.HashMap;
import java.util.Map;

import okhttp3.Call;

public class InformationDisclosurePresenter extends BasePresenter<InformationDisclosureContract.View>
        implements InformationDisclosureContract.Presenter {
    @Override
    public void getMenuList(boolean isloading) {
        Map<String, Object> params = new HashMap<>();
        params.put("marketId", "PDBLN");
        HttpRequestUtils.getInstance().request(params, HttpInterConst.INFORMATION_DISCLOSURE_QUERYPARENT, new MvpNetCallback<InformationDisclosureBean>(getView(), isloading) {
            @Override
            public void onError(Call call, Exception e, int id) {
                super.onError(call, e, id);
                // 失败回调 判断界面是否销毁
                if (!isViewAttached()) {
                    return;
                }
                getView().getMenuListFailed();
            }

            @Override
            public void onResponse(InformationDisclosureBean response, int id) {
                super.onResponse(response, id);
                if (!isViewAttached()) {
                    return;
                }
                if (response != null) {
                    if ("0".equals(response.getStatus())) {
                        getView().getMenuListSuccess(response);
                    } else {
                        if (!TextUtils.isEmpty(response.getMessage())) {
                            ToastUtils.showShort(response.getMessage());
                        }
                    }
                }
            }
        });
    }

    @Override
    public void getMenu2List(String levelOneGuid ,boolean isloading) {
        Map<String, Object> params = new HashMap<>();
        params.put("marketId", "PDBLN");
        params.put("levelOneGuid", levelOneGuid);
        HttpRequestUtils.getInstance().request(params, HttpInterConst.INFORMATION_DISCLOSURE_CHANGEINFORMATIONTYPEIDNEW, new MvpNetCallback<InformationDisclosure2Bean>(getView(), isloading) {
            @Override
            public void onError(Call call, Exception e, int id) {
                super.onError(call, e, id);
                // 失败回调 判断界面是否销毁
                if (!isViewAttached()) {
                    return;
                }
                getView().getMenu2ListFailed();
            }

            @Override
            public void onResponse(InformationDisclosure2Bean response, int id) {
                super.onResponse(response, id);
                if (!isViewAttached()) {
                    return;
                }
                if (response != null) {
                    if ("0".equals(response.getStatus())) {
                        getView().getMenu2ListSuccess(response);
                    } else {
                        if (!TextUtils.isEmpty(response.getMessage())) {
                            ToastUtils.showShort(response.getMessage());
                        }
                    }
                }
            }
        });
    }
}
